{{extend '../_layouts/home.html'}}

{{block 'title'}}{{'多人博客 - 首页'}}{{/block}}

{{block 'body'}}
<section class="container">
  {{include '../_partials/settings-nav.html'}}
  <div class="col-md-5">
    <form id="profile_form">
      <div class="form-group">
        <label for="exampleInputEmail1">账号</label>
        <p class="form-control-static">{{ user.email }}</p>
      </div>
      <div class="form-group">
        <label for="nickname">昵称</label>
        <input type="text" class="form-control" value="{{ user.nickname }}" name="nickname" id="nickname" placeholder="">
      </div>
      <div class="form-group">
        <label for="bio">介绍</label>
        <textarea class="form-control" name="bio" rows="3">{{ user.bio }}</textarea>
      </div>
      <div class="form-group">
        <label for="gender">性别</label>
        <div>
          <label class="radio-inline">
            {{ if user.gender === 0 }}
            <input type="radio" checked name="gender" id="gender1" value="0"> 男
            {{ else }}
            <input type="radio" name="gender" id="gender1" value="0"> 男
            {{ /if }}
          </label>
          <label class="radio-inline">
            {{ if user.gender === 1 }}
            <input type="radio" checked name="gender" id="gender2" value="1"> 女
            {{ else }}
            <input type="radio" name="gender" id="gender2" value="1"> 女
            {{ /if }}
          </label>
          <label class="radio-inline">
            {{ if user.gender === 2 }}
            <input type="radio" checked name="gender" id="gender3" value="2"> 保密
            {{ else }}
            <input type="radio" name="gender" id="gender3" value="2"> 保密
            {{ /if }}
          </label>
        </div>
      </div>
      <div class="form-group">
        <label for="birthday">生日</label>
        <input type="text" name="birthday" value="{{ user.birthday }}" class="form-control" id="birthday" placeholder="请按照格式2019-09-20 13:53:00">
      </div>
      <button type="submit" class="btn btn-success">保存</button>
    </form>
  </div>
  <div class="col-md-2 profile-avatar">
    <dl>
      <dt>头像设置</dt>
      <dd>
        <img class="avatar" width="150" height="150" src="{{ user.avatar }}" alt="">
        <div>
          <button class="btn btn-default" href="">Upload new picture</button>
        </div>
      </dd>
    </dl>
  </div>
</section>
<script src="/node_modules/jquery/dist/jquery.js"></script>
<script>
    $('#profile_form').on('submit', function (e) {
      e.preventDefault()
      var formData = $(this).serialize()
      console.log(formData)
      $.ajax({
        url: '/settings/profile',
        type: 'post',
        data: formData,
        dataType: 'json',
        success: function (data) {
          var err_code = data.err_code
          if (err_code === 0) {
            // window.alert('注册成功！')
            // 服务端重定向针对异步请求无效
            window.location.href = '/'
          } else {
            window.alert(data.message)
            window.location.reload()
          }
        }
      })
    })
  </script>
{{/block}}